package config

import (
	"github.com/golang-module/dongle"
)

func DESEncode(text string) string {
	cipher := dongle.NewCipher()
	cipher.SetMode(dongle.CBC)                 // CBC、ECB、CFB、OFB、CTR、GCM
	cipher.SetPadding(dongle.PKCS7)            // No、Zero、PKCS5、PKCS7
	cipher.SetKey(GetConfig().WebUI.TokenAuth) // key 长度必须是 8
	cipher.SetIV("12345678")
	return dongle.Encrypt.FromString(text).ByDes(cipher).ToHexString()
}

func DESDecode(pass string) string {
	cipher := dongle.NewCipher()
	cipher.SetMode(dongle.CBC)                 // CBC、ECB、CFB、OFB、CTR、GCM
	cipher.SetPadding(dongle.PKCS7)            // No、Zero、PKCS5、PKCS7
	cipher.SetKey(GetConfig().WebUI.TokenAuth) // key 长度必须是 8
	cipher.SetIV("12345678")
	return dongle.Decrypt.FromHexString(pass).ByDes(cipher).ToString() // hello world
}
